package arrAndstr;

/*
	226. 翻转二叉树
 */
public class T226 {

	public static void main(String[] args) {
		TreeNode treeNode = new TreeNode(4);
		treeNode.left = new TreeNode(2);
		treeNode.left.left = new TreeNode(1);
		treeNode.left.right = new TreeNode(3);
		treeNode.right = new TreeNode(7);
		treeNode.right.left = new TreeNode(6);
		treeNode.right.right = new TreeNode(9);

		TreeNode result = invertTree(treeNode);

	}

	public static class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode() {
		}

		TreeNode(int val) {
			this.val = val;
		}

		TreeNode(int val, TreeNode left, TreeNode right) {
			this.val = val;
			this.left = left;
			this.right = right;
		}
	}

	public static TreeNode invertTree(TreeNode root) {
		if (root == null) return root;

		root = new TreeNode(root.val, root.right, root.left);

		root.left = invertTree(root.left);
		root.right = invertTree(root.right);

		return root;
	}
}
